/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cloudbus.cloudsim.power.models.scheduling.test;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.power.models.scheduling.Client;
import org.cloudbus.cloudsim.power.models.scheduling.Middleware;

/**
 *
 * @author Márcio Costa Junior
 */
public class TwoMidOneService {
    
    private static int midNumber = 2;
    private static int clientsNumber = 1;
    
    public static void main(String[] argv){
        
         Log.printLine("Two Middlewares and One Service");
         ArrayList<Middleware> md;
         ArrayList<ArrayList<Client>> clients;
         
         md = new ArrayList<Middleware>();
      
        clients = new ArrayList<ArrayList<Client>>();
         
         //Setting the CloudSim proprieties
	 int num_user = 1; 
	 Calendar calendar = Calendar.getInstance();
	 boolean trace_flag = false; 
	 CloudSim.init(num_user, calendar, trace_flag);
         
         int frontEndId[] = new int[midNumber]; 
         int ids = 0;
         int size = 20;
         int fixedValue = size;
         
         try {
            //Middleware # , one service offered and 2000 MIPS separating it from the next class
            md.add(new Middleware("Mid_1", 1, 2000));
            md.add(new Middleware("Mid_2", 1, 2000));
        } catch (Exception ex) {
            Logger.getLogger(TwoMidOneService.class.getName()).log(Level.SEVERE, null, ex);
        }
           
         for(int i = 0; i < midNumber; i++){
             //Creating the Front-Ends with Four hosts, one processor each.
             md.get(i).createFrontEnds(4, 1);
                      
            //Configurating the data center
            md.get(i).createLocalDatacenters(1000, 10000, 1000000, 100000,
                                10.0, 3.0, (long) 0.05, (long) 0.001, (long) 0.0, 250,
                                0.7, 3.0, "Linux", "x86", "Xen");
            
            frontEndId[i] = md.get(i).getClassList().get(0).getFrontEnd().getId();
            
            ArrayList<Client> auxClients = new ArrayList<Client>();
            
            for(int j = 0; j < clientsNumber; j++){
                    auxClients.add(new Client("Client_" + j, i + j, md, i));
                    int[] mips = { 250, 500, 750, 1000 };
                    auxClients.get(j).createVms(frontEndId[i], ids, size, mips, 1, 128, 2500, 2500, "Xen");
                    auxClients.get(j).createCloulets(frontEndId[i], ids, size,150000, 1, 300, 300);
                    
                    md.get(i).getClassList().get(j).submitRequestList(auxClients.get(j).getVmList(), auxClients.get(j).getClList());
                    md.get(i).getClassList().get(j).createEstimator((int)fixedValue);
                    md.get(i).getClassList().get(j).getFrontEnd().setEstimator(md.get(i).getClassList().get(j).getEstimator());
             
                    
                    ids += size;
                    size += size;
            }
                      
            clients.add(auxClients);
            
         }
         
         for(int i = 0; i < midNumber - 1; i++){
             md.get(i).getClassList().get(0).getFrontEnd().setNext(md.get(i + 1).getClassList().get(0).getFrontEnd());
         }
         
         md.get(midNumber - 1).getClassList().get(0).getFrontEnd().setNext(null);
         
         
         CloudSim.startSimulation();
         
         CloudSim.stopSimulation();
         
         
         
    }
    
}
